#!/usr/bin/env node

import fs from 'fs';
import path from 'path';
import chalk from 'chalk';

function js() {
  const jsFile = fs.existsSync('./src/console.js')
    ? './src/console.js'
    : fs.existsSync('./console.js')
      ? './console.js'
      : undefined;

  if (jsFile) {
    require(path.resolve(jsFile));
    return true;
  }

  return false;
};

function ts() {
  const tsFile = fs.existsSync('./src/console.ts')
    ? './src/console.ts'
    : fs.existsSync('./console.ts')
      ? './console.ts'
      : undefined;

  if (tsFile) {
    require('ts-node/register');
    require(path.resolve(tsFile));
    return true;
  }

  return false;
}

if (!js() && !ts()) {
  console.error(chalk.red('File "./src/console.{js|ts}" or "./console.{js|ts}" doesn\'t exists.'));
  process.exit(1);
}
